﻿/*
 * Copyright (C) 2012, Jesus Requejo <jesus.requejo@gmail.com> 
 * Licensed under Microsoft Public License (Ms-PL)
 * http://www.microsoft.com/en-us/openness/licenses.aspx#MPL
*/

namespace Infrastructure {

   using System;
   using System.ServiceProcess;

   public enum LoaderServiceStatus {
      Running,
      Other
   }

   public class WindowsServicesManager {      

      const string ServiceName = @"LoaderService";
      ServiceController m_controller;

      public WindowsServicesManager() {
         m_controller = new ServiceController(ServiceName);
      }

      public LoaderServiceStatus GetServiceStatus() {
         try {
            m_controller.Refresh();
            var status = m_controller.Status;
            if (status == ServiceControllerStatus.Running) {
               return LoaderServiceStatus.Running;
            }
         }
         catch (Exception) {
            return LoaderServiceStatus.Other;
         }
         return LoaderServiceStatus.Other;
      }
   }
}
